package com.mysafe.provision.model.tag;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;


@Entity
@Table(schema = "sfe", name = "en_tag")
@SequenceGenerator(schema = "sfe", name = "seq_en_tag", allocationSize = 1)
public class Tag implements Serializable, Comparable<Tag> {
	
	private static final long serialVersionUID = -3273391706573166653L;

	@Id
	@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "seq_en_tag")
	@Column(name = "id_tag")
	private Integer id;
	private String name;
	
	public Tag() {
	}
	
	public Tag(Integer id) {
		this.id = id;
	}
	public Tag(String name) {
		this.name = name;
	}
	public Tag(Integer id, String name) {
		this.id = id;
		this.name = name;
	}
	
	@Override
	public int compareTo(Tag o) {
		return this.name.compareToIgnoreCase(o.getName());
	}
	
	@Override
	public boolean equals(Object obj) {
		boolean equals = false;
		if (obj instanceof Tag) {
			Tag other = (Tag)obj;
			if (id != null && other.getId() != null) {
				equals = id.equals(other.getId());
			} else if (name != null && other.getName() != null) {
				equals = name.equalsIgnoreCase(other.getName());
			}
		}
		return equals;
	}
	
	@Override
	public String toString() {
		if (name != null) {
			return name;
		}
		return super.toString();
	}
	
	/**
	 * @return the id
	 */
	public Integer getId() {
		return id;
	}
	/**
	 * @param id the id to set
	 */
	public void setId(Integer id) {
		this.id = id;
	}
	
	/**
	 * @return the name
	 */
	public String getName() {
		return name;
	}
	/**
	 * @param name the name to set
	 */
	public void setName(String name) {
		this.name = name;
	}

}
